<template>
    <div class="page home">
        <a class="tag" href="http://mp.weixin.qq.com/s?__biz=MzAxMTU0MDMyMg==&mid=402229786&idx=1&sn=1d66c8ffd6613b1d5f225c6b49a275d2&scene=1&srcid=0407nL11uENghrxRMrK8Gpis&from=groupmessage&isappinstalled=0#wechat_redirect"></a>
        <div class="title"></div>
        <div class="info">
            <div class="head"></div>
            <div class="inner">
                <h2 class="text">公告栏</h2>
                {{{notice|contentFilter}}}
                <i class="finger"></i>
            </div>
        </div>
        <div class="line"></div>
        <div class="msg-box">
            <p v-for="val in msgList">
                {{val.nick_name}} 刚刚 获得了 <span>{{val.amount}}</span> {{val.type}}
            </p>
        </div>
        <div class="toobar weui_grids" v-el:toolbar>
            <a href="#task"><div class="item weui_grid">做任务</div></a>
            <a href="#lucky"><div class="item weui_grid">刮奖</div></a>
            <a><div class="item weui_grid" @click="boxShow">个人中心</div></a>
        </div>
        <div class="tool-box weui_grids" v-show="box" v-el:toolbox>
            <a @click="luckyShow"><div class="item weui_grid">每日领券</div></a>
            <a href="#user"><div class="item weui_grid">用户资料</div></a>
            <a href="#prefer"><div class="item weui_grid">偏好设置</div></a>
            <a href="#wallet"><div class="item weui_grid">我的钱包</div></a>
        </div>
        <Dialog class="check-in" :show.sync="lucky" type="confirm" cancel-btn="关闭" confirm-btn="去抽奖" title=" " :cancel="luckyHide" :confirm="goLucky">
            <i class="close" @click="luckyHide"></i>
            <h1>恭喜你！</h1>
            <p>签到获得<span>奖券＋{{reward}}</span></p>
            <p class="des">本奖品由［小吧］提供</p>
        </Dialog>
        <msg :data="errorData"></msg>
    </div>
</template>

<script type="text/ecmascript-6">
    import "./style/home.less"
    import Dialog from '../weui/Dialog.vue'
    import server from '../lib/server'
    import {setSession,getSession} from '../lib/session'
    import Msg from '../components/Msg.vue'
    import fixed from '../lib/fixed'
    export default {
      data () {
        return {
            notice:'',
            msgList:[],
            lucky:false,
            box:false,
            serverData:getSession(),
            errorData:{},
            reward:0
        }
      },
      filters:{
        contentFilter(val){
            return val.replace('\n','<br>');
        }
      },
      components:{
        Dialog,Msg
      },
      methods:{
        boxShow(){
            this.box=!this.box;
        },
        boxHide(){
            this.box=false;
        },
        luckyShow(){
            server('/P/U/getTickt',{
                session_id:this.serverData.session_id
            }).success((response)=>{
                if(response.code==1){
                    this.reward=response.data;
                    this.serverData.ticketNum+=this.reward;
                    this.serverData.ticketTotal+=this.reward;
                    setSession(this.serverData);
                    this.boxHide();
                    this.lucky=true;
                }else{
                    if(response.code==19){
                        this.errorData={
                            show:true,
                            type:'login'
                        };
                    }else{
                        this.errorData={
                            show:true,
                            type:'error',
                            msg:response.msg
                        };
                    }
                }
            });
        },
        luckyHide(){
            this.lucky=false;
        },
        goLucky(){
            this.lucky=false;
            this.$router.go('/lucky');
        }
      },
      created () {
        server('/P/Public/getnotice_wx').success((response)=>{
            if(response.code==1){
                this.notice=response.data;
            }else{
                this.errorData={
                    show:true,
                    type:'error',
                    msg:response.msg
                };
            }
        });
        server('/P/Public/getscrollinfo').success((response)=>{
            if(response.code==1){
                this.msgList=response.data;
            }else{
                this.errorData={
                    show:true,
                    type:'error',
                    msg:response.msg
                };
            }
        });
      },
      ready(){
        fixed(this.$el,this.$els.toolbar,$(window).height()-2.5*parseFloat($('html').css('fontSize')));
        fixed(this.$el,this.$els.toolbox,$(window).height()-12.3*parseFloat($('html').css('fontSize')));
      },
      destroyed () {
      }
    }
</script>
